package com.yanqu.road.entity.activity.newyearbag;

import com.yanqu.road.entity.enums.activity.newyearbag.eNewYearBagType;

import java.util.concurrent.ConcurrentHashMap;

public class NewYearBagLimitData {

    private int lv;
    private ConcurrentHashMap<Integer, Long> xianJinMap = new ConcurrentHashMap<>();
    private ConcurrentHashMap<Integer, Long> tongBaoMap = new ConcurrentHashMap<>();
    private ConcurrentHashMap<Integer, Long> skinMap = new ConcurrentHashMap<>();


    // ----------------------------------------


    public long getAllNum(eNewYearBagType type) {
        ConcurrentHashMap<Integer, Long> map = new ConcurrentHashMap<>();
        if (type == eNewYearBagType.TongBao) {
            map = tongBaoMap;
        } else if (type == eNewYearBagType.XianJin) {
            map = xianJinMap;
        } else if (type == eNewYearBagType.Skin) {
            map = skinMap;
        }
        return map.values().stream().mapToLong(Long::longValue).sum();
    }

    public long getTodayNum(eNewYearBagType type, int day) {
        ConcurrentHashMap<Integer, Long> map = new ConcurrentHashMap<>();
        if (type == eNewYearBagType.TongBao) {
            map = tongBaoMap;
        } else if (type == eNewYearBagType.XianJin) {
            map = xianJinMap;
        } else if (type == eNewYearBagType.Skin) {
            map = skinMap;
        }
        return map.getOrDefault(day, 0L);
    }

    public long getSumTodayNum(eNewYearBagType type, int day) {
        ConcurrentHashMap<Integer, Long> map = new ConcurrentHashMap<>();
        if (type == eNewYearBagType.TongBao) {
            map = tongBaoMap;
        } else if (type == eNewYearBagType.XianJin) {
            map = xianJinMap;
        } else if (type == eNewYearBagType.Skin) {
            map = skinMap;
        }

        long sum = 0;
        for (int i = 1; i <= day; i++) {
            sum += map.getOrDefault(i, 0L);
        }
        return sum;
    }

    public void addNum(eNewYearBagType type, int day, long num) {
        ConcurrentHashMap<Integer, Long> map = new ConcurrentHashMap<>();
        if (type == eNewYearBagType.TongBao) {
            map = tongBaoMap;
        } else if (type == eNewYearBagType.XianJin) {
            map = xianJinMap;
        } else if (type == eNewYearBagType.Skin) {
            map = skinMap;
        }
        long oldVal = map.getOrDefault(day, 0L);
        map.put(day, oldVal + num);
    }


    // ----------------------------------------

    public NewYearBagLimitData(int lv) {
        this.lv = lv;
    }

    public NewYearBagLimitData() {
    }

    public int getLv() {
        return lv;
    }

    public void setLv(int lv) {
        this.lv = lv;
    }

    public ConcurrentHashMap<Integer, Long> getXianJinMap() {
        return xianJinMap;
    }

    public void setXianJinMap(ConcurrentHashMap<Integer, Long> xianJinMap) {
        this.xianJinMap = xianJinMap;
    }

    public ConcurrentHashMap<Integer, Long> getTongBaoMap() {
        return tongBaoMap;
    }

    public void setTongBaoMap(ConcurrentHashMap<Integer, Long> tongBaoMap) {
        this.tongBaoMap = tongBaoMap;
    }

    public ConcurrentHashMap<Integer, Long> getSkinMap() {
        return skinMap;
    }

    public void setSkinMap(ConcurrentHashMap<Integer, Long> skinMap) {
        this.skinMap = skinMap;
    }
}
